<?php

class SettingsController extends CController
{
	public function actionIndex()
	{
		$this->setPageTitle('Настройки сайта');
		
		$records = CActiveRecordData::getArray(
			SiteSettings::model()->findAll()
		);
	 	
	 	$data = array();
	 	foreach ($records as $val) {
	 		$data[$val['alias']] = $val; 
	 	}
		
		$this->render('index', array(
			'data' => $data
		));
	}
	
	public function actionUpdate()
	{
		$data = $_POST;
		
		foreach ($data as $key => $value) {
			SiteSettings::model()->updateAll(array('value' => $value), 'alias=:alias', array(':alias' => $key));
		}
		
		FlashMessage::saveInfo(array(
			'title'  => 'Инфо',
			'text'   => 'Данные сохранены'
		));
		
		$this->redirect('/admin/settings/');
	}
}